package cn.monkey.io.transport.core.reactive;

import cn.monkey.io.transport.core.Exchange;
import reactor.core.publisher.Mono;

/**
 * 创建Exchange
 *
 * @param <C>
 * @param <EXCHANGE>
 */
public interface ReactiveExchangeFactory<C, EXCHANGE extends Exchange> {

    /**
     * @param key      {@link EXCHANGE#id()}
     * @param exchange Exchange可以层层嵌套。如：
     *                 <pre><code>
     *                 SimpleNettyExchangeFactory simpleNettyExchangeFactory = new SimpleNettyExchangeFactory();
     *
     *                 InboundReceivedExchangeFactory<Channel, NettyExchange, String> inboundReceivedExchangeFactory
     *                 = new InboundReceivedExchangeFactory<>(filterChain, String.class, Schedulers.newSingle("test")) {};
     *
     *                 CombinedExchangeFactory<Channel, NettyExchange> exchangeFactory = new CombinedExchangeFactory<>(simpleNettyExchangeFactory, inboundReceivedExchangeFactory);
     *                 </code></pre>
     * @param c        其他参数
     * @return Exchange
     * 如果执行失败，则通过{@link Mono#error} 取获取错误信息
     */
    Mono<EXCHANGE> apply(String key,
                         Exchange exchange,
                         C c);
}
